/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package groupe;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.xml.sax.SAXException;



/**
 *
 * @author Ter Murga Victor
 */
public class GroupeApp extends JFrame implements ActionListener{
    private JPanel mainPanel;
    private String description= "PERL permet de visualiser les informations du profil";
    private JButton creation;
    private JTextArea label2;
    private JLabel imageLabel;
    private JButton open; //nouveau bouton open
    private JButton exit;
    private JSeparator separator;

    public GroupeApp() {
        ResourceMap resourceMap = Application.getInstance(groupe.App.class).getContext().getResourceMap(App.class);
        setTitle(resourceMap.getString("Application.title")+" ("+resourceMap.getString("Application.description")+")");
        initComponents(resourceMap);
    }

    private void initComponents(ResourceMap resourceMap){
        mainPanel=new JPanel();
        open = new JButton("<html><center>Modifier un profil <br> de groupe</center></html>");
        exit = new JButton("Quitter GROUPE");
        creation = new JButton("<html><center>Créer un profil<br>de groupe</center></html>");
        label2 = new JTextArea("Groupe vous permet de faire un certain nombre d'opérations sur les profils, concernant leur \n structure et les données qui y sont associées. \n Il permet notamment d'établir des profils de \n groupes à partir des profils des élèves.");
        label2.setFont(new Font("Calibri",Font.PLAIN,15));
        imageLabel = new JLabel();
        separator = new JSeparator(javax.swing.SwingConstants.VERTICAL);

        creation.setActionCommand("creation");
        open.setActionCommand("open");
        exit.setActionCommand("exit");

        mainPanel.setBackground(new Color(215,228,242));
        mainPanel.setPreferredSize(new Dimension(570, 610));

        creation.addActionListener(this);
        open.addActionListener(this);
        //open.setPreferredSize(new Dimension(145,65));

        exit.addActionListener(this);

        imageLabel.setIcon(resourceMap.getIcon("jlabel1.icon"));
        imageLabel.setName("imageLabel");
        imageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        imageLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        imageLabel.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
        imageLabel.setVerticalTextPosition(javax.swing.SwingConstants.CENTER);
        separator.setPreferredSize(new Dimension(20,280));
        separator.setForeground(new Color(172, 168, 153));
        separator.setBackground(Color.white);
        label2.setLineWrap(true);
        label2.setBackground(new Color(215,228,242));
        label2.setFocusable(false);

        //  label2.setEnabled(false);
        
        

        //separator.setLocation(50, 70);
        /*JLabel label = new JLabel("dhsdfhsdghsh");
        label.setSize(20, 20);*/

        GroupLayout mainPanelLayout = new GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(0, 0, 0)
                        .addComponent(imageLabel, GroupLayout.PREFERRED_SIZE, 300, GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(0, 0, 0)
                        .addComponent(label2, 300, 300, 300)
                        .addGap(30, 30, 30)))
                .addComponent(separator, 15, 15, 15)
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(creation, 145,145,145))
                   // .addGroup(mainPanelLayout.createSequentialGroup()
                     //   .addGap(17, 17, 17)
                     //   .addComponent(open, 145,145,145))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(exit, 145, 145, 145)))
                .addGap(20, 20, 20))
        );

        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(imageLabel, GroupLayout.PREFERRED_SIZE,460, GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, 0)
                        .addComponent(label2, 100,100,100))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(separator, 500, 500, 500))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(180, 180, 180)
                        .addComponent(creation, 65,65,65)
                        .addGap(20, 20, 20)
                        //.addComponent(open, 65, 65, 65)
                        //.addGap(20, 20, 20)
                        .addComponent(exit, 65,65,65)))
                .addContainerGap(97, Short.MAX_VALUE))
        );


        getContentPane().add(mainPanel);
        setResizable(false);
        //Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        //System.out.println("longueur ecran= "+screen.width+" / fen= "+getSize().width);
        //setUndecorated(true);
        //setLocation((screen.width - 500)/2,(screen.height - 320)/2);
        //setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        pack();
        //setVisible(true);
        //setComponent(mainPanel);
        //setMenuBar(menuBar);
    }

    public void actionPerformed(ActionEvent e) {
        String c = e.getActionCommand();
        if(c.equals("open")){
            JFileChooser jfc = Utility.ouvrirOpenBox(null,null);
            if(jfc!=null){
                String URL = jfc.getSelectedFile().getAbsolutePath();
                dispose();
                try {
                    try {
                        App.getApplication().show(new GroupeView(URL));
                    } catch (TransformerConfigurationException ex) {
                        Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (TransformerException ex) {
                        Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } catch (ParserConfigurationException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SAXException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } else if (c.equals("exit")){
            Utility.exit();
        } else if (c.equals("creation")){
          
//JFileChooser jfc2 =Utility.ouvrirOpenBox(Utility.getPath(this,"/Fichiers utilisateur/Profils Eprofilea"), null);
            JFileChooser jfc2 = Utility.ouvrirOpenBox2("E:/TER/Eprofileaderniereversion/Eprofilea_TER_2009/Fichiers utilisateur/Structure de profils",null);
            if(jfc2!=null){
                String URL = jfc2.getSelectedFile().getAbsolutePath();
                dispose();
                try {
                    try {
                        App.getApplication().show(new GroupeView(URL));
                    } catch (TransformerConfigurationException ex) {
                        Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (TransformerException ex) {
                        Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } catch (ParserConfigurationException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SAXException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(GroupeApp.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }


}
